package com.pwt.common;

/**
 * @author zhangyi
 */
public enum ResultCode {

    /* 成功状态码 */
    SUCCESS(200, "成功"),

    DATA_EXISTED(204,"数据已存在"),

    DATA_NOT_FOUND(404,"数据未找到"),

    /* 参数错误：10001-19999 */
    PARAM_IS_INVALID(10001, "参数无效"),
    PARAM_IS_BLANk(10002, "参数为空"),
    PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
    PARAM_NOT_COMPLETE(10004, "参数缺失"),
    UPLOAD_FAILED(10005, "上传失败"),

    /* 用户错误：20001-29999*/
    USER_NOT_LOGGED_IN(20001, "用户未登录"),
    USER_LOGIN_ERROR(20002, "账号不存在或密码错误"),
    USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
    USER_NOT_EXIST(20004, "用户不存在"),
    USER_HAS_EXISTED(20005, "用户已存在"),
    USER_NOT_ALLOWED(20006, "用户未认证"),
    USER_PHONE_EXISTED(20007,"手机号已被注册"),
    USER_EMAIL_EXISTED(20008,"邮箱地址已被注册"),
    USER_SIGNUP_FAILURE(20009,"用户注册失败"),
    USER_TOkEN_VALID(20010,"用户令牌失效"),
    USER_SAVE_FAILED(20011,"用户保存失败"),
    USER_MODIFY_FAILED(20012,"用户修改失败"),

    PARENT_MENU_NOT_FOUND(20100,"上级菜单不存在"),
    MENU_NOT_FOUND(20101,"菜单不存在"),
    MENU_HAS_CHILDREN(20102,"菜单包含子菜单"),

    /* 权限错误：70001-79999 */
    PERMISSION_NO_ACCESS(70001, "无访问权限");


    private Integer code;

    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }
}
